/*
package test.my.com.myapplicationtest.RxjavaTest;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.telecom.Call;
import android.util.Log;
import android.widget.ImageView;


import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import butterknife.Bind;
import butterknife.ButterKnife;
import rx.Observable;
import rx.Observer;
import test.my.com.myapplicationtest.R;

*/
/**
 * Author : Cooper
 * Time : 2017/4/21  11:47
 * Description : RxJava test
 *//*


public class RxjavaActivity extends Activity {

    public final String TAG = RxjavaActivity.this.getClass().getName();
    @Bind(R.id.iv_image)
    ImageView ivImage;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aty_rxjava_layout);
        ButterKnife.bind(this);
        initFlowable();
    }

    private void init() {
        Observable.create(new ObservableOnSubscribe<Drawable>() {
            @Override
            public void subscribe(ObservableEmitter<Drawable> e) throws Exception {
                Log.e(TAG,"ah === subscribe");
                Drawable drawable = RxjavaActivity.this.getResources().getDrawable(R.drawable.banner);
                e.onNext(drawable);
            }
        }).subscribe(new Observer<Drawable>() {
            @Override
            public void onSubscribe(Disposable d) {
                Log.e(TAG,"ah === onSubscribe");
            }

            @Override
            public void onNext(Drawable value) {
                Log.e(TAG,"ah === onNext");
                ivImage.setImageDrawable(value);
            }

            @Override
            public void onError(Throwable e) {
                Log.e(TAG,"ah === onError");
            }

            @Override
            public void onComplete() {
                Log.e(TAG,"ah === onComplete");
            }
        });
    }

    private void testThreadRxjava() {
        Observable obsrvable = Observable.create(new ObservableOnSubscribe() {
            @Override
            public void subscribe(ObservableEmitter e) throws Exception {
                Log.e(TAG,"ah subscribeOn == current thread ==== "+Thread.currentThread().getName());
                Thread.sleep(2000);
                e.onNext("");
            }
        }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());

        obsrvable.subscribe(new Observer() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(Object value) {
                Log.e(TAG,"ah observeOn == current thread ==== "+Thread.currentThread().getName());
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    private void initMap() {
        Observable observable = Observable.create(new ObservableOnSubscribe() {
            @Override
            public void subscribe(ObservableEmitter e) throws Exception {
                e.onNext(11);
                e.onNext(12);
                e.onNext(13);
            }
        }).map(new Function<Integer, String>(){
            @Override
            public String apply(Integer integer) throws Exception {
                return "this is result === "+integer;
            }
        });
        observable.subscribe(new Consumer<String>(){
            @Override
            public void accept(String s) throws Exception {
                Log.e(TAG,"Consumer === "+s);
            }
        });
    }

    private void initFlatMap() {
        Observable observable = Observable.create(new ObservableOnSubscribe<Integer>() {
            @Override
            public void subscribe(ObservableEmitter<Integer> e) throws Exception {
                e.onNext(23);
                e.onNext(24);
                e.onNext(25);
            }
        }).flatMap(new Function<Integer, ObservableSource<?>>() {
            @Override
            public ObservableSource<String> apply(Integer integer) throws Exception {
                List<String> list = new ArrayList<String>();
                for(int i=0;i<3;i++) {
                    list.add("这是 测试一下 === " + integer);
                }
                return Observable.fromIterable(list).delay(100, TimeUnit.MILLISECONDS);
            }
        });
        observable.subscribe(new Consumer<String>(){
            @Override
            public void accept(String s) throws Exception {
                Log.e(TAG,"Consumer === "+s);
            }
        });

    }

    private void initZip() {
        Observable<Integer> observable1 = Observable.create(new ObservableOnSubscribe<Integer>() {
            @Override
            public void subscribe(ObservableEmitter<Integer> e) throws Exception {
                e.onNext(1);
                e.onNext(2);
                e.onNext(3);
            }
        }).subscribeOn(Schedulers.io());
        Observable<String> observable2 = Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> e) throws Exception {
                e.onNext("A");
                e.onNext("B");
                e.onNext("C");
            }
        }).subscribeOn(Schedulers.io());

        Observable.zip(observable1, observable2, new BiFunction<Integer, String, String>() {
            @Override
            public String apply(Integer integer, String s) throws Exception {
                return integer+" == "+s;
            }
        }).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                Log.d(TAG, "onSubscribe");
            }

            @Override
            public void onNext(String value) {
                Log.d(TAG, "onNext:  " + value);
            }

            @Override
            public void onError(Throwable e) {
                Log.d(TAG, "onError");
            }

            @Override
            public void onComplete() {
                Log.d(TAG, "onComplete");
            }
        });
    }

    private void initFlowable() {
        Flowable<Integer> upstream = Flowable.create(new FlowableOnSubscribe<Integer>() {
            @Override
            public void subscribe(FlowableEmitter<Integer> emitter) throws Exception {
                Log.d(TAG, "emit 1");
                emitter.onNext(1);
                Log.d(TAG, "emit 2");
                emitter.onNext(2);
                Log.d(TAG, "emit 3");
                emitter.onNext(3);
                Log.d(TAG, "emit complete");
                emitter.onComplete();
            }
        }, BackpressureStrategy.ERROR).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
        Subscriber<Integer> downstream = new Subscriber<Integer>() {
            @Override
            public void onSubscribe(Subscription s) {
                Log.d(TAG, "onSubscribe");
                s.request(Long.MAX_VALUE);
            }

            @Override
            public void onNext(Integer integer) {
                Log.d(TAG, "onNext: " + integer);
            }

            @Override
            public void onError(Throwable t) {
                Log.d(TAG, "onError");
            }

            @Override
            public void onComplete() {
                Log.d(TAG, "onComplete");
            }
        };
        upstream.subscribe(downstream);
    }
}
*/
